package com.shawn.spring.boot.mybatis.mapper;

import com.shawn.spring.boot.mybatis.entity.User;
import com.shawn.spring.boot.mybatis.entity.UserExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.session.RowBounds;
import org.springframework.stereotype.Repository;

@Repository
@Mapper
public interface UserMapper {
  /**
   * This method was generated by MyBatis Generator. This method corresponds to the database table
   * t_user
   *
   * @mbg.generated Sun Aug 30 18:19:25 CST 2020
   */
  long countByExample(UserExample example);

  /**
   * This method was generated by MyBatis Generator. This method corresponds to the database table
   * t_user
   *
   * @mbg.generated Sun Aug 30 18:19:25 CST 2020
   */
  int deleteByExample(UserExample example);

  /**
   * This method was generated by MyBatis Generator. This method corresponds to the database table
   * t_user
   *
   * @mbg.generated Sun Aug 30 18:19:25 CST 2020
   */
  @Delete({"delete from t_user", "where user_id = #{userId,jdbcType=BIGINT}"})
  int deleteByPrimaryKey(Long userId);

  /**
   * This method was generated by MyBatis Generator. This method corresponds to the database table
   * t_user
   *
   * @mbg.generated Sun Aug 30 18:19:25 CST 2020
   */
  @Insert({
    "insert into t_user (username, password, ",
    "salt, email, mobile, ",
    "is_deleted, create_time, ",
    "update_time)",
    "values (#{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, ",
    "#{salt,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{mobile,jdbcType=VARCHAR}, ",
    "#{isDeleted,jdbcType=TINYINT}, #{createTime,jdbcType=TIMESTAMP}, ",
    "#{updateTime,jdbcType=TIMESTAMP})"
  })
  @SelectKey(
      statement = "SELECT LAST_INSERT_ID()",
      keyProperty = "userId",
      before = false,
      resultType = Long.class)
  int insert(User record);

  /**
   * This method was generated by MyBatis Generator. This method corresponds to the database table
   * t_user
   *
   * @mbg.generated Sun Aug 30 18:19:25 CST 2020
   */
  int insertSelective(User record);

  /**
   * This method was generated by MyBatis Generator. This method corresponds to the database table
   * t_user
   *
   * @mbg.generated Sun Aug 30 18:19:25 CST 2020
   */
  List<User> selectByExampleWithRowbounds(UserExample example, RowBounds rowBounds);

  /**
   * This method was generated by MyBatis Generator. This method corresponds to the database table
   * t_user
   *
   * @mbg.generated Sun Aug 30 18:19:25 CST 2020
   */
  List<User> selectByExample(UserExample example);

  /**
   * This method was generated by MyBatis Generator. This method corresponds to the database table
   * t_user
   *
   * @mbg.generated Sun Aug 30 18:19:25 CST 2020
   */
  @Select({
    "select",
    "user_id, username, password, salt, email, mobile, is_deleted, create_time, update_time",
    "from t_user",
    "where user_id = #{userId,jdbcType=BIGINT}"
  })
  @ResultMap("com.shawn.spring.boot.mybatis.mapper.UserMapper.BaseResultMap")
  User selectByPrimaryKey(Long userId);

  /**
   * This method was generated by MyBatis Generator. This method corresponds to the database table
   * t_user
   *
   * @mbg.generated Sun Aug 30 18:19:25 CST 2020
   */
  int updateByExampleSelective(@Param("record") User record, @Param("example") UserExample example);

  /**
   * This method was generated by MyBatis Generator. This method corresponds to the database table
   * t_user
   *
   * @mbg.generated Sun Aug 30 18:19:25 CST 2020
   */
  int updateByExample(@Param("record") User record, @Param("example") UserExample example);

  /**
   * This method was generated by MyBatis Generator. This method corresponds to the database table
   * t_user
   *
   * @mbg.generated Sun Aug 30 18:19:25 CST 2020
   */
  int updateByPrimaryKeySelective(User record);

  /**
   * This method was generated by MyBatis Generator. This method corresponds to the database table
   * t_user
   *
   * @mbg.generated Sun Aug 30 18:19:25 CST 2020
   */
  @Update({
    "update t_user",
    "set username = #{username,jdbcType=VARCHAR},",
    "password = #{password,jdbcType=VARCHAR},",
    "salt = #{salt,jdbcType=VARCHAR},",
    "email = #{email,jdbcType=VARCHAR},",
    "mobile = #{mobile,jdbcType=VARCHAR},",
    "is_deleted = #{isDeleted,jdbcType=TINYINT},",
    "create_time = #{createTime,jdbcType=TIMESTAMP},",
    "update_time = #{updateTime,jdbcType=TIMESTAMP}",
    "where user_id = #{userId,jdbcType=BIGINT}"
  })
  int updateByPrimaryKey(User record);

  @Insert("insert into t_user_role (role_id, user_id) values (#{roleId}, #{userId})")
  int insertUserRole(@Param("roleId") long roleId, @Param("userId") long userId);

  @Select("select * from t_user order by user_id")
  @ResultMap("com.shawn.spring.boot.mybatis.mapper.UserMapper.BaseResultMap")
  List<User> selectAll();

  @Select("select * from t_user order by user_id")
  @ResultMap("com.shawn.spring.boot.mybatis.mapper.UserMapper.BaseResultMap")
  List<User> selectWithRowBounds(RowBounds rowBounds);

  @Select("select * from t_user order by user_id")
  @ResultMap("com.shawn.spring.boot.mybatis.mapper.UserMapper.BaseResultMap")
  List<User> selectWithParams(@Param("pageNum") int pageNum, @Param("pageSize") int pageSize);
}
